import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Button Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const ButtonDemoPage(),
    );
  }
}

class ButtonDemoPage extends StatelessWidget {
  const ButtonDemoPage({super.key});

  // 按钮点击事件
  void _onPressed() {
    debugPrint("按钮被点击");
  }

  // ElevatedButton 演示
  Widget buildElevatedButtonDemo() {
    return ElevatedButton(onPressed: _onPressed, child: Text("normal"));
  }

  // TextButton 演示
  Widget buildTextButtonDemo() {
    return TextButton(onPressed: _onPressed, child: Text("normal"));
  }

  // OutlinedButton 演示
  Widget buildOutlinedButtonDemo() {
    return OutlinedButton(onPressed: _onPressed, child: Text("normal"));
  }

  // IconButton 演示
  Widget buildIconButtonDemo() {
    return IconButton(icon: Icon(Icons.thumb_up), onPressed: _onPressed);
  }

  // 带图标的按钮演示
  Widget buildButtonWithIconDemo() {
    return Column(
      children: [
        ElevatedButton.icon(
          icon: Icon(Icons.send),
          label: Text("发送"),
          onPressed: _onPressed,
        ),
        SizedBox(height: 10),
        OutlinedButton.icon(
          icon: Icon(Icons.add),
          label: Text("添加"),
          onPressed: _onPressed,
        ),
        SizedBox(height: 10),
        TextButton.icon(
          icon: Icon(Icons.info),
          label: Text("详情"),
          onPressed: _onPressed,
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text('Button Demo'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text(
                'ElevatedButton 演示',
                style: Theme.of(context).textTheme.headlineSmall,
              ),
              SizedBox(height: 10),
              buildElevatedButtonDemo(),
              SizedBox(height: 20),

              Text(
                'TextButton 演示',
                style: Theme.of(context).textTheme.headlineSmall,
              ),
              SizedBox(height: 10),
              buildTextButtonDemo(),
              SizedBox(height: 20),

              Text(
                'OutlinedButton 演示',
                style: Theme.of(context).textTheme.headlineSmall,
              ),
              SizedBox(height: 10),
              buildOutlinedButtonDemo(),
              SizedBox(height: 20),

              Text(
                'IconButton 演示',
                style: Theme.of(context).textTheme.headlineSmall,
              ),
              SizedBox(height: 10),
              Center(child: buildIconButtonDemo()),
              SizedBox(height: 20),

              Text(
                '带图标的按钮演示',
                style: Theme.of(context).textTheme.headlineSmall,
              ),
              SizedBox(height: 10),
              buildButtonWithIconDemo(),
            ],
          ),
        ),
      ),
    );
  }
}
